

/////////////////////////////////////////////////////////////////////////////

package sheep.view.Component;

/////////////////////////////////////////////////////////////////////////////

import java.util.LinkedList;
import javax.swing.table.AbstractTableModel;


/////////////////////////////////////////////////////////////////////////////
import org.jdesktop.swingx.JXTable;
import sheep.model.WorkGroup;
import sheep.model.Worker;

/**
 *
 * @author geek
 * 
 * Classe representant un travailleur repertorie
 */
public class GroupTableModel extends AbstractTableModel {
  private Object[] columnNames;
  private LinkedList<WorkGroup> data;
  
  public GroupTableModel(Object[] columns, LinkedList<WorkGroup> data) {
    this.columnNames = columns;
    this.data = data;
  }
  
  public int getRowCount() {
    return data.size();
  }

  public int getColumnCount() {
    return columnNames.length;
  }
  
  public void setData(LinkedList<WorkGroup> data) {
    this.data = data;
  }
  
  public void setHeaders(Object[] headers) { this.columnNames = headers; }
  
  public Object[][] getData() { 
    Object[][] tab = new Object[getRowCount()][getColumnCount()];
    int i =0;
    for (WorkGroup w : data){
      tab[i][0]= data.get(i).getId();
      tab[i][1]= data.get(i).getName();
      tab[i][2]= data.get(i).getWorkersList().size();
    }
    return tab; 
  }
 
  public Object[] getHeaders() { return columnNames; }

  public Object getValueAt(int row, int col) {
    if (col == 0){
      return data.get(row).getId();
    }else if (col==1){
      return data.get(row).getName();
    }else if (col==2){
      return data.get(row).getWorkersList().size();
    }
    return null;
  }
  
  public static void setTableHeaders(JXTable table, Object[] headers) {
    for(int i=0; i<headers.length; i++)
      table.getColumnModel().getColumn(i).setHeaderValue(headers[i]);
  }
}

/////////////////////////////////////////////////////////////////////////////
